#include "stdafx.h"

/*************************************
* Append a new mapping item to Mapping Table
***/
void MsgMappingTable::Append(const MsgMappingItem& Item)
{
	MsgMappingItem* pNew = new MsgMappingItem(Item.msg, Item.ProcFunc);
	if(pStart == 0)
	{
		pStart = pNew;
		return;
	}	
	MsgMappingItem* pTemp = pStart;
	while(pTemp->pNext != 0)
	{
		pTemp = pTemp->pNext;
	}
	pTemp->pNext = pNew;
}

/*************************************
 * Clear the Mapping Table and release resources
 ***/
void MsgMappingTable::Clear()
{
	if (pStart ==0)
	{
		return;
	}
	MsgMappingItem* pTemp = pStart;
	while (pStart != 0)
	{
		pTemp =  pStart;
		pStart = pStart->pNext;
		delete pTemp;
	}
	pStart = 0;
	pTemp = 0;	
}

/*************************************
 * Find the MSGPROCFUNC corresponding to msg
 ***/
MSGPROCFUNC MsgMappingTable::Find(int msg)
{
	MsgMappingItem* pTemp = pStart;
	while (pTemp !=0 )
	{
		if(pTemp->msg == msg)
			return pTemp->ProcFunc;
		pTemp = pTemp->pNext;
	}
	return 0;
}
